﻿using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using MiniFox.Components;
using MiniFox.Components.Configurations;
using MiniFox.Configurations;
using MiniFox.Utility;
using MiniFox.Web.AppStarting;
using MiniFox.Web.Configurations;

namespace MiniFox.Web
{
    /// <summary>
    /// 
    /// </summary>
    public class HostingStartup : IHostingStartup
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="builder"></param>
        public virtual void Configure(IWebHostBuilder builder)
        {
            builder.ConfigureAppConfiguration(configurationBuilder =>
            {
                var config = configurationBuilder.Build();
                ConfigurationFactory.Initialize(config);
                ComponentFactory.Initialize(ConfigurationFactory.GetConfig<ComponentContainerConfiguration>());


            });
            builder.UseStartup((webHostBuilderContext) =>
            {
                var startup = new Startup(webHostBuilderContext.Configuration, webHostBuilderContext.HostingEnvironment);
                startup.Initialize();
                return startup;
            });

        }
    }
}
